import mongoose from 'mongoose';
import { formatDateByNow } from '~/utils/util.date';

export interface IUserCollection extends mongoose.Document {
	userId: mongoose.Schema.Types.ObjectId;
	resourceId: mongoose.Schema.Types.ObjectId;
	createdAt?: string;
	updatedAt?: string;
}

// 客户端用户资源收藏
const UserCollectionSchema = new mongoose.Schema<IUserCollection>(
	{
		userId: {
			type: mongoose.Schema.Types.ObjectId,
			required: true,
		},
		resourceId: {
			type: mongoose.Schema.Types.ObjectId,
			required: true,
		},
		createdAt: {
			type: String,
			default: formatDateByNow(),
		},
		updatedAt: {
			type: String,
			default: formatDateByNow(),
		},
	},
	{
		collection: 'user_collections',
	}
);

export const UserCollectionModel = mongoose.model('UserCollection', UserCollectionSchema);
